const util = require('../../../utils/util.js');
var user = require('../../../services/user.js');
var app = getApp();
Page({
  data: {
    userInfo: {},
    teacherbase: {},
    isLogin: false
  },
  onLoad: function () {
    //console.log(app.globalData);
    
  },
  onReady: function () {

  },
  onShow: function () {
    let userInfo = wx.getStorageSync('userInfo');
    let token = wx.getStorageSync('token');
    // 页面显示
    if (userInfo && token) {
      app.globalData.userInfo = userInfo;
      app.globalData.token = token;
      this.setData({
        isLogin: true
      });
    }
    this.setData({
      userInfo: app.globalData.userInfo
    });
    this.getuserbase();
  },
  onGotUserInfo:function(){
    user.loginByWeixin().then(res => {
      this.setData({
        userInfo: res.data.userInfo
      });
      app.globalData.userInfo = res.data.userInfo;
      app.globalData.token = res.data.token;
      this.setData({
        isLogin: true
      });
      this.getuserbase();
    }).catch((err) => {
      console.log(err)
    });
  },
  getuserbase:function(){
    let that = this;
    util.request('user/getuserbase', 'GET').then(function (res) {
      console.log(res.data);
      if (res.errno === 0) {
        that.setData({
          teacherbase: res.data.teacherbase || {},
        });
      }
    });
  },
  goaddlesson:function(){//进入添加课程
    wx.navigateTo({
      url: `/pages/mine/addlesson/addlesson`
    })
  },
  goteacherlessonlist:function(){
    wx.navigateTo({
      url: `/pages/mine/teacherlessonlist/teacherlessonlist`
    })
  },
  goCollection:function(){
    wx.navigateTo({
      url: `/pages/mine/collectioncenter/collectioncenter`
    })
  },
  goLiveroom:function() {
    wx.navigateTo({
      url: `/pages/mine/liveroom/liveroom`
    })
  },
  goAccountbalance:function(){
    wx.navigateTo({
      url: `/pages/mine/accountbalance/accountbalance`
    })
  },
  goOrderrecord: function () {
    wx.navigateTo({
      url: `/pages/mine/orderrecord/orderrecord`
    })
  },
  goHelp:function(){
    wx.navigateTo({
      url: `/pages/mine/help/help`
    })
  },
  goLecturer:function(){
    wx.navigateTo({
      url: `/pages/mine/lecturer/lecturer`
    })
  }

})